import React from 'react';
import {Spin, Card, Button, Table, Divider, Collapse, Checkbox, message as msg, Anchor, Popover} from 'antd';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import PropTypes from 'prop-types';
import {currency, repairType, claimApprovedResult, claimAthType, customerType, faultType, fileType} from '../Enum';
import routes from './routes';
import {DATETIME_FORMAT, TABLE, DATE_FORMAT, FILES_API} from '../constants';
import {PERMISSION} from './constants';
import {conventEnumValueToString, formatDateTime, formatAmount, onDownloadHistory} from '../utils';
import {getDetail, abandonData, submitData, returnData, getcClaimHistoriesList} from './api';
import {injectIntl} from './intl';
import {hasPermissions} from './utils';
import WrappedPopconfirm from '../common/WrappedPopconfirm';
import styles from './style.css';
import ClaimHistoryPanel from './PageAdd/ClaimHistoryPanel';
import ImageUpload from './PageAdd/ImageUpload';
const {Link} = Anchor;
const {Description} = DescriptionList;
const {Panel} = Collapse;
class DetailPanel extends React.PureComponent {
    state = {
        isFetching: false,
        data: {},
        details: [],
        claimWorkItemDetails: [],
        claimResultDetails: [],
        claimAthDetails: [],
        claimMaterialDetails: [],
        claimHistories: {},
    }
    componentDidMount() {
        this.getDetailInfo();
        window.scrollTo(0, 0);
    }
    getDetailInfo = () => {
        const id = this.props.id;
        this.setState({isFetching: true});
        getDetail(id)
            .then(res => {
                if(res.ok) {
                    this.setState({
                        isFetching: false,
                        data: res.data,
                        details: res.data.details,
                        claimWorkItemDetails: res.data.claimWorkItemDetails,
                        claimResultDetails: res.data.claimResultDetails,
                        claimAthDetails: res.data.claimAthDetails,
                        claimMaterialDetails: res.data.claimMaterialDetails,
                        claimApplyCountersignResults: res.data.claimApplyCountersignResults
                    });
                    this.getClaimHistories(res.data.vin, res.data.createTime);
                } else
                    this.setState(({
                        isFetching: false
                    }));
            });
    }
    
    getClaimHistories = (vin, createTime) => {
        this.setState({
            loading: true
        });
        getcClaimHistoriesList({
            vin,
            createTime
        })
            .then(res => {
                if(res.ok)
                    this.setState({
                        loading: false,
                        claimHistories: res.data
                    });
                else
                    this.setState(({
                        loading: false
                    }));
            });
    }
    onCancel = () => {
        this.props.history.push(routes.query.url());
    }
    onClickSubmitBtn = () => {
        this.setState({loading: true});
        const data = {
            rowVersion: this.state.data.rowVersion
        };
        submitData(this.state.data.id, data)
            .then(res => {
                this.setState({loading: false});
                if(res.ok)
                    this.props.successReturn();
            });
    }
    onClickAbandon = () => {
        this.setState({loading: true});
        const data = {
            rowVersion: this.state.data.rowVersion
        };
        abandonData(this.state.data.id, data)
            .then(res => {
                this.setState({loading: false});
                if(res.ok)
                    this.props.successReturn();
            });
    }
    onClickReturnBtn = () => {
        this.setState({loading: true});
        const data = {
            rowVersion: this.state.data.rowVersion
        };
        returnData(this.state.data.id, data)
            .then(res => {
                this.setState({loading: false});
                if(res.ok)
                    this.props.successReturn();
            });
    }
    onClickApproveBtn = () => {
        if(this.state.data.isExistsExchangeRate === true)
            return msg.warn(this.props.intl.formatMessage({
                id: 'detailPanel.message.isExistsExchangeRateTrue',
                defaultMessage: '预申请单币种与美元存在多条有效的汇率信息，请维护后再审核'
            }));
        if(this.state.data.isExistsExchangeRate === false)
            return msg.warn(this.props.intl.formatMessage({
                id: 'detailPanel.message.isAllowApproveFales',
                defaultMessage: '预申请单币种与美元不存在 汇率信息，请维护后再审核'
            }));
        if(!this.state.data.isAllowApprove)
            return msg.warn(this.props.intl.formatMessage({
                id: 'detailPanel.message.isAllowApprove',
                defaultMessage: '多级审核配置不正确'
            }));
        this.props.history.push(routes.approve.format(this.props.id));
    }
    onClickSearchHistoryBtn = () => {
        window.open(
            `#dcs/afterSales/claimHistory/applyHistory?vin=${this.state.data.vin}`
        );
    };
    onClickDownload = e => {
        const {id, applyid} = e.target.dataset;
        onDownloadHistory({
            filePath: id,
            fileName: applyid
        });
    }
    onClickCreate = () => {
        window.open(`#/dcs/afterSales/claim/add?id=${this.props.id}`);
    }
    render() {
        const {data, details, claimWorkItemDetails, claimMaterialDetails, claimAthDetails, claimResultDetails, claimHistories, claimApplyCountersignResults} = this.state;
        const {formatMessage} = this.props.intl;
        const operations = [];
        const claimAthDetailTuPhoto = claimAthDetails.find(v => v.type === claimAthType.图片资料 && v.fileType === fileType.图片) || {};
        const claimAthDetailTuFile = claimAthDetails.find(v => v.type === claimAthType.图片资料 && v.fileType === fileType.文件) || {};
        const claimAthDetailFaPhoto = claimAthDetails.find(v => v.type === claimAthType.发票扫描图片 && v.fileType === fileType.图片) || {};
        const claimAthDetailFaFile = claimAthDetails.find(v => v.type === claimAthType.发票扫描图片 && v.fileType === fileType.文件) || {};
        if(hasPermissions(this.props.permissions, PERMISSION.update) && hasPermissions(data.options, PERMISSION.update))
            operations.push(<Button key="update" href={`#${routes.update.format(this.props.id)}`} size="small">{
                formatMessage({
                    id: 'detailPanel.update',
                    defaultMessage: '编辑'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.approve) && hasPermissions(data.options, PERMISSION.approve))
            operations.push(<Button key="approve" onClick={this.onClickApproveBtn} size="small">{
                formatMessage({
                    id: 'detailPanel.approve',
                    defaultMessage: '审核'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.adjust) && hasPermissions(data.options, PERMISSION.adjust))
            operations.push(<Button key="adjust" href={`#${routes.adjust.format(this.props.id)}`} size="small">{
                formatMessage({
                    id: 'detailPanel.adjust',
                    defaultMessage: '调整'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.countersigner) && hasPermissions(data.options, PERMISSION.countersigner))
            operations.push(<Button key="countersigner" href={`#${routes.countersigner.format(this.props.id)}`} size="small">{
                formatMessage({
                    id: 'detailPanel.countersigner',
                    defaultMessage: '会签'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.abandon) && hasPermissions(data.options, PERMISSION.abandon))
            operations.push(<WrappedPopconfirm
                key="abandon"
                id={this.props.id}
                placement="topLeft"
                onConfirm={this.onClickAbandon}
                title={formatMessage({
                    id: 'detailPanel.validate.abandon',
                    defaultMessage: '是否确认作废？'
                })}>
                <Button key="abandon" size="small">{
                    formatMessage({
                        id: 'detailPanel.abandon',
                        defaultMessage: '作废'
                    })
                }</Button>
            </WrappedPopconfirm>);
        if(hasPermissions(this.props.permissions, PERMISSION.claim) && hasPermissions(data.options, PERMISSION.claim))
            operations.push(<Button key="claim" data-id={this.props.id} data-code={this.props.code} onClick={this.onClickCreate} size="small">{
                formatMessage({
                    id: 'detailPage.btn.claim',
                    defaultMessage: '索赔'
                })
            }</Button>);
        const columnMaterials = [
            {
                title: formatMessage({
                    id: 'detailPanel.materialTablePanel.usedPartCode',
                    defaultMessage: '旧件编号'
                }),
                dataIndex: 'usedPartCode',
                render: (text, r) => (<Popover content={r.productCategoryCode} title={formatMessage({
                    id: 'workItemDetailPanel.partProductCategoryCodes',
                    defaultMessage: '车型'
                })}>
                    {text}
                </Popover>)
            },
            {
                title: formatMessage({
                    id: 'detailPanel.materialTablePanel.usedPartName',
                    defaultMessage: '旧件名称'
                }),
                dataIndex: 'usedPartName'
            },
            {
                title: formatMessage({
                    id: 'detailPanel.materialTablePanel.isCaused',
                    defaultMessage: '是否主损件'
                }),
                dataIndex: 'isCaused',
                render: text => text ? formatMessage({
                    id: 'detailPanel.materialTablePanel.isCausedYes',
                    defaultMessage: '是'
                }) : formatMessage({
                    id: 'detailPanel.materialTablePanel.isCausedNo',
                    defaultMessage: '否'
                })
            },
            {
                title: formatMessage({
                    id: 'detailPanel.materialTablePanel.quantity',
                    defaultMessage: '数量'
                }),
                dataIndex: 'quantity'
            }
        ];
        if(!this.props.isMoneyVisible)
            columnMaterials.splice(4, 0,
                {
                    title: formatMessage({
                        id: 'detailPanel.materialTablePanel.price',
                        defaultMessage: '单价'
                    }),
                    dataIndex: 'price',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.materialTablePanel.mgmtRate',
                        defaultMessage: '管理费率'
                    }),
                    dataIndex: 'mgmtRate',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.materialTablePanel.mgmtFee',
                        defaultMessage: '管理费'
                    }),
                    dataIndex: 'mgmtFee',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.materialTablePanel.materialFee',
                        defaultMessage: '材料费合计'
                    }),
                    dataIndex: 'materialFee',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.materialTablePanel.totalFee',
                        defaultMessage: '费用合计'
                    }),
                    dataIndex: 'totalFee',
                    render: text => formatAmount(text)
                });
        const columnWorkItems = [
            {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.usedPartCode',
                    defaultMessage: '备件编号'
                }),
                dataIndex: 'usedPartCode',
                render: (text, r) => (<Popover content={r.partProductCategoryCodes} title={formatMessage({
                    id: 'workItemDetailPanel.partProductCategoryCodes',
                    defaultMessage: '车型'
                })}>
                    {text}
                </Popover>)
            }, {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.workItemCode',
                    defaultMessage: '维修项目编号'
                }),
                dataIndex: 'workItemCode'
            },
            {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.workItemName',
                    defaultMessage: '维修项目名称'
                }),
                dataIndex: 'workItemName'
            },
            {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.productCategoryCode',
                    defaultMessage: '车型'
                }),
                dataIndex: 'productCategoryCode'
            },
            {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.laborHour',
                    defaultMessage: '工时'
                }),
                dataIndex: 'laborHour'
            },
            {
                title: formatMessage({
                    id: 'detailPanel.workItemDetailPanel.remark',
                    defaultMessage: '备注'
                }),
                dataIndex: 'remark'
            }
        ];
        if(!this.props.isMoneyVisible)
            columnMaterials.splice(5, 0,
                {
                    title: formatMessage({
                        id: 'detailPanel.workItemDetailPanel.laborPrice',
                        defaultMessage: '工时单价'
                    }),
                    dataIndex: 'laborPrice',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.workItemDetailPanel.laborFee',
                        defaultMessage: '工时费'
                    }),
                    dataIndex: 'laborFee',
                    render: text => formatAmount(text)
                });
        const colums = [{
            title: formatMessage({
                id: 'detailPanel.usedPartCode',
                defaultMessage: '旧件编号'
            }),
            dataIndex: 'usedPartCode'
        },
        {
            title: formatMessage({
                id: 'detailPanel.usedPartName',
                defaultMessage: '旧件名称'
            }),
            dataIndex: 'usedPartName'
        },
        {
            title: formatMessage({
                id: 'detailPanel.unit',
                defaultMessage: '计量单位'
            }),
            dataIndex: 'unit'
        },
        {
            title: formatMessage({
                id: 'detailPanel.usedQty',
                defaultMessage: '索赔用量'
            }),
            dataIndex: 'usedQty'
        },
        {
            title: formatMessage({
                id: 'detailPanel.quantity',
                defaultMessage: '计价数量'
            }),
            dataIndex: 'quantity'
        }];
        if(!this.props.isMoneyVisible)
            columnMaterials.splice(5, 0,
                {
                    title: formatMessage({
                        id: 'detailPanel.price',
                        defaultMessage: '单价'
                    }),
                    dataIndex: 'price',
                    render: text => formatAmount(text)
                },
                {
                    title: formatMessage({
                        id: 'detailPanel.materialFee',
                        defaultMessage: '材料费合计'
                    }),
                    dataIndex: 'materialFee',
                    render: text => formatAmount(text)
                });
        const columResults = [{
            title: formatMessage({
                id: 'detailPanel.approverName',
                defaultMessage: '审核人'
            }),
            dataIndex: 'approverName'
        },
        {
            title: formatMessage({
                id: 'detailPanel.approveComment',
                defaultMessage: '审核意见'
            }),
            dataIndex: 'approveComment'
        },
        {
            title: formatMessage({
                id: 'detailPanel.approvedResult',
                defaultMessage: '审核结果'
            }),
            dataIndex: 'approvedResult',
            render: text => conventEnumValueToString(claimApprovedResult, text)
        },
        {
            title: formatMessage({
                id: 'detailPanel.approveTime',
                defaultMessage: '审核时间'
            }),
            dataIndex: 'approveTime',
            render: text => formatDateTime(text, DATETIME_FORMAT)
        }];
        const columCountersigns = [{
            title: formatMessage({
                id: 'detailPanel.countersignerName',
                defaultMessage: '会签人姓名'
            }),
            dataIndex: 'countersignerName'
        },
        {
            title: formatMessage({
                id: 'detailPanel.countersignedComment',
                defaultMessage: '会签意见'
            }),
            dataIndex: 'countersignedComment'
        },
        {
            title: formatMessage({
                id: 'detailPanel.countersignedResult',
                defaultMessage: '会签结果'
            }),
            dataIndex: 'countersignedResult'
        },
        {
            title: formatMessage({
                id: 'detailPanel.countersignedTime',
                defaultMessage: '会签时间'
            }),
            dataIndex: 'countersignedTime',
            render: text => formatDateTime(text, DATETIME_FORMAT)
        }];
        return (
            <div>
                <Spin spinning={this.state.isFetching}>
                    {operations.length > 0 && <Card className={styles.optionBtn}>{operations}</Card>}
                    <Anchor className={styles.toc_affix}
                        showInkInFixed={true}>
                        <Link href={`${location.hash}#components-anchor-common`} title={this.props.intl.formatMessage({
                            id: 'detailPanel.anchor.common',
                            defaultMessage: '基本信息'
                        })} />
                        <Link href={`${location.hash}#components-anchor-vehicleInfo`} title={this.props.intl.formatMessage({
                            id: 'detailPanel.anchor.vehicleInfo',
                            defaultMessage: '车辆信息'
                        })} />
                        <Link href={`${location.hash}#components-anchor-material`} title={this.props.intl.formatMessage({
                            id: 'detailPanel.anchor.material',
                            defaultMessage: '材料信息'
                        })} />
                        {!data.isOtherArea && <Link href={`${location.hash}#components-anchor-claimHistory`} title={this.props.intl.formatMessage({
                            id: 'newPanel.anchor.claimHistory',
                            defaultMessage: '历史索赔'
                        })} />}
                    </Anchor>
                    <Collapse className={styles.collapseMarginTop}>
                        <Panel id="components-anchor-common" header={<DescriptionList>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.code',
                                defaultMessage: '预授权单号'
                            })}>{data.code}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.brandCode',
                                defaultMessage: '品牌'
                            })}>{data.brandCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.vin',
                                defaultMessage: 'VIN'
                            })}>{data.vin}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.repairType',
                                defaultMessage: '索赔类型'
                            })}>{conventEnumValueToString(repairType, data.repairType)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.repairCode',
                                defaultMessage: '维修单号'
                            })}>{data.repairCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.subClaimApplyCode',
                                defaultMessage: '经销商预授权单号'
                            })}>{data.subClaimApplyCode}
                            </Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.checkDate',
                                defaultMessage: '检查日期'
                            })}>{formatDateTime(data.checkDate, DATE_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.salesDealerCode',
                                defaultMessage: '经销商编号'
                            })}>{data.subDealerCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.mileage',
                                defaultMessage: '行驶里程'
                            })}>{data.mileage}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.saleDate',
                                defaultMessage: '实销日期'
                            })}>{formatDateTime(data.saleDate, DATE_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.shipDate',
                                defaultMessage: '发车日期'
                            })}>{formatDateTime(data.shipDate, DATE_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.productionDate',
                                defaultMessage: '生产日期'
                            })}>{formatDateTime(data.productionDate, DATE_FORMAT)}</Description>
                            
                        </DescriptionList>} key="1">
                            <DescriptionList>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.isOtherArea',
                                    defaultMessage: '是否跨区域索赔'
                                })}>
                                    {data.isOtherArea ? 'Yes' : 'No'}
                                </Description>
                                {
                                    data.repairType === repairType.备件索赔 &&
                                    <Description term={formatMessage({
                                        id: 'detailPanel.operation.partPurchasedDate',
                                        defaultMessage: '自费购件时间'
                                    })}>{formatDateTime(data.partPurchasedDate, DATE_FORMAT)}</Description>
                                }
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.shipmentPort',
                                    defaultMessage: '维修日期'
                                })}>{formatDateTime(data.repairDate, DATE_FORMAT)}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.artisan',
                                    defaultMessage: '技术分析员'
                                })}>{data.artisan}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.createName',
                                    defaultMessage: '填报人'
                                })}>{data.creatorName}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.createTime',
                                    defaultMessage: '申请日期'
                                })}>{formatDateTime(data.createTime, DATE_FORMAT)}</Description>
                            </DescriptionList>
                        </Panel>
                        <Panel id="components-anchor-vehicleInfo" header={<DescriptionList>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.productCategoryCode',
                                defaultMessage: '车型编号'
                            })}>{data.productCategoryCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.customerSoldType',
                                defaultMessage: '客户性质'
                            })}>{conventEnumValueToString(customerType, data.customerSoldType)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.country',
                                defaultMessage: '国家'
                            })}>{data.country}</Description>
                        </DescriptionList>} key="2">
                            <DescriptionList>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.wholesaleDealerCode',
                                    defaultMessage: '总代'
                                })}>{`(${data.wholesaleDealerCode})${data.wholesaleDealerName}`}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.currency',
                                    defaultMessage: '币种'
                                })}>{conventEnumValueToString(currency, data.currency)}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.engineCode',
                                    defaultMessage: '发动机号'
                                })}>{data.engineCode}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.transmissionSn',
                                    defaultMessage: '变速箱号'
                                })}>{data.transmissionSn}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.productCategoryName',
                                    defaultMessage: '车型名称'
                                })}>{data.productCategoryName}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.annoucementNumber',
                                    defaultMessage: '公告号'
                                })}>{data.annoucementNumber}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.isKD',
                                    defaultMessage: 'CBU/KD索赔'
                                })}>{data.isKD === true && formatMessage({
                                        id: 'detailPanel.operation.kd',
                                        defaultMessage: 'KD'
                                    })}
                                    {data.isKD === false && formatMessage({
                                        id: 'detailPanel.operation.cbu',
                                        defaultMessage: 'CBU'
                                    })}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.customerName',
                                    defaultMessage: '用户姓名'
                                })}>{data.customerName}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.cellPhoneNumber',
                                    defaultMessage: '用户电话'
                                })}>{data.cellPhoneNumber}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.companyName',
                                    defaultMessage: '用户公司'
                                })}>{data.companyName}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.address',
                                    defaultMessage: '用户地址'
                                })}>{data.address}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.email',
                                    defaultMessage: '用户Email'
                                })}>{data.email}</Description>
                            </DescriptionList>
                        </Panel>
                    </Collapse>
                    <Collapse defaultActiveKey={['1', '2', '3', '4', '5', '6', '7']}>
                        <Panel id="components-anchor-material" header={<div>{formatMessage({
                            id: 'detailPanel.table.claimMaterialDetails',
                            defaultMessage: '材料清单'
                        })}<Divider type="vertical" />{formatMessage({
                            id: 'detailPanel.operation.supplierCode',
                            defaultMessage: '供应商'
                        })}{': '}{data.supplierCode}<Divider type="vertical" />{formatMessage({
                            id: 'detailPanel.operation.faultType',
                            defaultMessage: '故障类型'
                        })}{': '}{conventEnumValueToString(faultType, data.faultType)}</div>} key="1">
                            <Table
                                className="white-space-nowrap"
                                columns={columnMaterials}
                                rowKey="usedPartId"
                                pagination={false}
                                dataSource={claimMaterialDetails}
                                {...TABLE} />
                            <DescriptionList className={styles.collapseMarginTop}>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.faultItem',
                                    defaultMessage: '故障代码'
                                })}><span className="value-font">({data.faultItemCode}) {data.faultItemName}</span></Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.faultMode',
                                    defaultMessage: '故障原因'
                                })}><span className="value-font">({data.faultModeCode}) {data.faultModeName}</span></Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.faultDescription',
                                    defaultMessage: '详细故障描述'
                                })}>{data.faultDescription}</Description>
                                {/* <Description term={formatMessage({
                                    id: 'detailPanel.operation.checkResul',
                                    defaultMessage: '检查分析结果'
                                })}>{data.checkResult}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.artisanResult',
                                    defaultMessage: '技术判断意见'
                                })}>{data.artisanResult}</Description>
                                <Description term={formatMessage({
                                    id: 'detailPanel.operation.dealerApproveComment',
                                    defaultMessage: '总代理商处理意见'
                                })}>{data.dealerApproveComment}</Description> */}
                            </DescriptionList>
                        </Panel>
                        <Panel header={formatMessage({
                            id: 'detailPanel.operation.attachment',
                            defaultMessage: '附件清单'
                        })} key="7">
                            {claimAthDetails && claimAthDetails.length > 0
                                ? <div>
                                    {
                                        (claimAthDetailTuPhoto || claimAthDetailTuFile) &&
                                        <DescriptionList title={formatMessage({
                                            id: 'detailPanel.card.attachmentTu',
                                            defaultMessage: '图片资料附件'
                                        })} size="large">
                                            {(claimAthDetailTuPhoto.attachments && claimAthDetailTuPhoto.attachments.length > 0) &&
                                            <div><ImageUpload fileList={claimAthDetailTuPhoto.attachments} isUpload={false}/>
                                                <Divider /></div>}
                                            {(claimAthDetailTuFile.attachments && claimAthDetailTuFile.attachments.length > 0) &&
                                                claimAthDetailTuFile.attachments.map(item => (<Description key={item.fileId}>
                                                    {item.filePath ? <a onClick={this.onClickDownload} key={item.fileId} data-id={item.filePath} data-applyid={item.fileName}>
                                                        {item.fileName}</a> : <a icon="download" download
                                                        href={`${FILES_API.files}/${item.fileId}`} size="small">{item.fileName}</a>}</Description>))}
                                        </DescriptionList>
                                    }
                                    <Divider className={styles.divider}/>
                                    {
                                        data.repairType === repairType.备件索赔 && (claimAthDetailFaPhoto || claimAthDetailFaFile) &&
                                        <DescriptionList title={formatMessage({
                                            id: 'detailPanel.card.attachmentFa',
                                            defaultMessage: '发票扫描图片附件'
                                        })} size="large">
                                            {(claimAthDetailFaPhoto.attachments && claimAthDetailFaPhoto.attachments.length > 0) &&
                                            <div><ImageUpload fileList={claimAthDetailTuPhoto.attachments} isUpload={false}/>
                                                <Divider /></div>}
                                            {(claimAthDetailFaFile.attachments && claimAthDetailFaFile.attachments.length > 0) &&
                                                claimAthDetailFaFile.attachments.map(item => (<Description key={item.fileId}>
                                                    <a icon="download" download
                                                        href={`${FILES_API.files}/${item.fileId}`} size="small">{item.fileName}</a></Description>))}
                                        </DescriptionList>
                                    }
                                </div>
                                : formatMessage({
                                    id: 'detailPanel.content.noAttachment',
                                    defaultMessage: '暂无附件'
                                })}
                        </Panel>
                        <Panel header={formatMessage({
                            id: 'detailPanel.table.claimWorkItemDetails',
                            defaultMessage: '项目清单'
                        })} key="2">
                            <Table
                                className="white-space-nowrap"
                                columns={columnWorkItems}
                                rowKey="id"
                                pagination={false}
                                dataSource={claimWorkItemDetails}
                                {...TABLE} />
                        </Panel>
                        <Panel header={formatMessage({
                            id: 'detailPanel.table.details',
                            defaultMessage: '辅料清单'
                        })} key="3">
                            <Table
                                className="white-space-nowrap"
                                columns={colums}
                                rowKey="usedPartId"
                                pagination={false}
                                dataSource={details}
                                {...TABLE} />
                        </Panel>
                        {!data.isOtherArea && <Panel id="components-anchor-claimHistory" header={formatMessage({
                            id: 'detailPanel.operation.claimHistory',
                            defaultMessage: '历史索赔信息'
                        })} key="4">
                            <ClaimHistoryPanel data={claimHistories} />
                        </Panel>}
                        <Panel header={formatMessage({
                            id: 'detailPanel.operation.claimResultDetails',
                            defaultMessage: '历史审核信息'
                        })} key="5">
                            <Table
                                className="white-space-nowrap"
                                columns={columResults}
                                rowKey="id"
                                pagination={false}
                                dataSource={claimResultDetails}
                                {...TABLE} />
                        </Panel>
                        {!this.props.isDealerUser && <Panel header={formatMessage({
                            id: 'detailPanel.operation.claimApplyCountersignResults',
                            defaultMessage: '历史会签信息'
                        })} key="6">
                            <Table
                                className="white-space-nowrap"
                                columns={columCountersigns}
                                rowKey="id"
                                pagination={false}
                                dataSource={claimApplyCountersignResults}
                                {...TABLE} />
                        </Panel>}
                    </Collapse>
                    {!this.props.isMoneyVisible &&
                    <Card title={formatMessage({
                        id: 'detailPanel.card.feeInfo',
                        defaultMessage: '索赔费用'
                    })}>
                        <DescriptionList>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.laborFee',
                                defaultMessage: '工时费'
                            })}>{formatAmount(data.laborFee)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.materialFee',
                                defaultMessage: '材料费'
                            })}>{formatAmount(data.materialFee)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.assiantFee',
                                defaultMessage: '辅料费'
                            })}>{formatAmount(data.assiantFee)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.mgmtFee',
                                defaultMessage: '管理费'
                            })}>{formatAmount(data.mgmtFee)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.operation.totalFee',
                                defaultMessage: '费用合计'
                            })}>{formatAmount(data.totalFee)}</Description>
                        </DescriptionList>
                    </Card>}
                </Spin>
                <div className="page-toolbar">
                    <Button type="primary" onClick={this.onCancel}>{this.props.intl.formatMessage({
                        id: 'detailPanel.operation.onCancel',
                        defaultMessage: '返回'
                    })}</Button>
                </div>
            </div>
        );
    }
}

DetailPanel.propTypes = {
    history: PropTypes.object,
    id: PropTypes.string,
    intl: PropTypes.object,
    isDealerUser: PropTypes.bool,
    isMoneyVisible: PropTypes.bool,
};

import {connect} from 'react-redux';
import {tableSearch} from './actions';
import selectorFactory from 'Shared/utils/immutableToJsSelectorFactory';
const getPermissions = selectorFactory(['page', 'domainData', 'permission', 'data']);
const mapStateToProps = (state, props) => ({
    permissions: getPermissions(state),
    isDealerUser: state.getIn((['page', 'domainData', 'initData', 'isDealerUser'])),
    isMoneyVisible: state.getIn((['page', 'domainData', 'initData', 'isMoneyVisible'])),
});
const mapDispatchToProps = (dispatch, props) => ({
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(DetailPanel));
